package stack

import (
	"strings"
)

func MinRemoveToMakeValid(s string) string {

	str_elements := strings.Split(s, "")
	stack := []int{}

	for i := range str_elements {
		if str_elements[i] == "(" {
			stack = append(stack, i)
		}

		if str_elements[i] == ")" {
			if len(stack) == 0 {
				str_elements[i] = ""
			} else {
				stack = stack[:len(stack)-1]
			}
		}
	}

	if len(stack) > 0 {
		for _, v := range stack {
			str_elements[v] = ""
		}
	}

	return strings.Join(str_elements, "")

}
